<?php
namespace Common\Models;
use Common\BaseModel;
class  FVerificationCodes extends BaseModel
{
	public $res;
	public $expire;
    public function initialize()
    {
        parent::initialize();
        $this->setSource('f_verification_codes');
    }



    public function check_phone($phone, $code)
    {
        $where['conditions'] = "recipient = $phone";
        $where['order']      = "id desc";

        $code_obj = $this->findFirst($where);

        if (!$code_obj) {
            return '未获取验证码!';
        }
        if ($code_obj->expire_at < date('Y-m-d H:i:s')) {
            return '验证码过期!请从新获取';
        }
        if ($code_obj->code != $code) {
            return '验证码错误!';
        }
        $code_obj->expire_at = date('Y-m-d H:i:s');
        if ($code_obj->save()) {
            return true;
        } else {
            return '验证码验证失败!';
        }
    }



}
